package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.ShiroUtils;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.entity.CorePlace;
import com.corechina.apex_osswords.service.ICorePlaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 地点管理 前端控制器
 * </p>
 *
 * @author cc
 * @since 2022-05-30
 */

@Api(tags = "地点管理")
@RestController
@RequestMapping("/core/place")
public class CorePlaceController {

    @Autowired
    private ICorePlaceService iCorePlaceService;

    @ApiOperation("新增")
    @SysLog("新增地点")
    @PostMapping("/add")
    public Response add(@RequestBody CorePlace corePlace) {
        if (iCorePlaceService.save(corePlace)) {
            return Response.ok();
        }
        return Response.error();
    }


    @ApiOperation("编辑")
    @SysLog("编辑地点")
    @PutMapping("/update")
    public Response update(@RequestBody CorePlace corePlace) {
        if (iCorePlaceService.updateById(corePlace)) {
            return Response.ok();
        }
        return Response.error();
    }

    @ApiOperation("删除")
    @SysLog("删除地点")
    @DeleteMapping("/del")
    public Response del(Integer id) {
        if (iCorePlaceService.updateIsDel(1, id) > 0) {
            return Response.ok();
        }
        return Response.error();
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(String name, Integer serviceId, Integer pageIndex, Integer pageSize) {
        return iCorePlaceService.getList(name, serviceId, ShiroUtils.getSeeAll().equals(1) ? null : ShiroUtils.getEnterpriseId(), pageIndex, pageSize);
    }

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return Response.ok(iCorePlaceService.getById(id));
    }


//    @ApiOperation("获取项目地址列表")
//    @GetMapping("/getPlaceList")
//    public Response getPlaceList(Integer projectId, Integer pageIndex, Integer pageSize) {
//        return iCorePlaceService.getPlaceList(projectId, pageIndex, pageSize);
//    }
}